package koction.model.consumer;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import koction.model.admin.AskSellerVO;
import koction.model.product.ProductVO;
import koction.model.seller.SellerVO;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class ConsumerDaoImpl implements ConsumerDao {
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public ConsumerVO findById(String id) {
		return sqlSessionTemplate.selectOne("consumer.findById",id);
	}

	@Override
	public int registerConsumer(ConsumerVO cvo) {
		return sqlSessionTemplate.insert("consumer.registerConsumer",cvo);
	}

	@Override
	public int updateConsumer(ConsumerVO cvo) {
		return sqlSessionTemplate.update("consumer.updateConsumer",cvo);
	}

	@Override
	public ConsumerVO loginConsumer(ConsumerVO cvo) {
		return sqlSessionTemplate.selectOne("consumer.loginConsumer",cvo);
	}

	@Override
	public int deleteConsumer(ConsumerVO cvo) {
		return sqlSessionTemplate.delete("consumer.deleteConsumer",cvo);
	}

	@Override
	public ConsumerVO findConsumerById(String id) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("consumer.findConsumerById", id);
	}

	@Override
	public void updatePoint(Map map) {
		sqlSessionTemplate.update("consumer.updatePoint",map);
	}

	@Override
	public void updateTotalPoint(Map map) {
		sqlSessionTemplate.update("consumer.updateTotalPoint",map);
	}

	@Override
	public void registerPurchaseList(Map map) {
		sqlSessionTemplate.insert("consumer.registerPurchaseList", map);
		System.out.println("okokokokok");
	}

	@Override
	public void updateProductInventory(Map map) {
		sqlSessionTemplate.update("product.updateProductInventory",map);
		
	}

	@Override
	public void registerSellList(Map map) {
		sqlSessionTemplate.insert("seller.registerSellList",map);
	}

	@Override
	public List<PurchaseListVO> getPurchaseList(Map map) {
		return sqlSessionTemplate.selectList("consumer.getPurchaseList", map);
	}
	@Override
	public ProductVO findProductById(int productId) {
		return sqlSessionTemplate.selectOne("product.findProductById", productId);
	}
	
	@Override
	public void deletePurchaseList(String purchaseNo) {
		sqlSessionTemplate.delete("consumer.deletePurchaseList", purchaseNo);
	}

	@Override
	public int getTotalPurchaseList(String id) {
		return sqlSessionTemplate.selectOne("consumer.getTotalPurchaseList", id);
	}
	
	@Override
	public SellerVO findSellerByConsumerId(String id) {
		return sqlSessionTemplate.selectOne("seller.findSellerByConsumerId",id);
	}

	@Override
	public void askSeller(AskSellerVO asvo) {
		this.sqlSessionTemplate.insert("consumer.askSeller",asvo);
	}
	
	@Override
	public GradeVO myGrade(Map map) {
		return sqlSessionTemplate.selectOne("consumer.mygrade",map);
	}

	@Override
	public int updateGrade(Map map) {
		return sqlSessionTemplate.update("consumer.updateGrade",map);
	}
	
}
